package com.slz3.business.module.systemManagement.sysPermissions.repository;

import com.slz3.business.module.systemManagement.sysPermissions.domain.SysPermissions;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.UUID;

public interface SysPermissionsRepository extends JpaRepository<SysPermissions, UUID>, JpaSpecificationExecutor<SysPermissions>, SysPermissionsCustomizedRepository {
    List<SysPermissions> queryByMenuUuid(UUID menuUuid);

    @Query("SELECT count(sp.uuid) FROM SysPermissions sp  " +
            "WHERE sp.serUri = :path  " +
            "AND sp.validFlag = 'VALID' " +
            "AND EXISTS ( " +
            " SELECT 1 FROM SysRolePermissions srp " +
            " JOIN SysRoleUser sr ON srp.roleUuid = sr.roleUuid " +
            " WHERE sr.userUuid = :loginUserUuid " +
            " AND srp.permissionUuid = sp.uuid " +
            ") ")
    int hasAuth(@Param("loginUserUuid") UUID loginUserUuid,@Param("path") String path);
}
